//
//  MoreNewsViewController.m
//  动漫之家
//
//  Created by 王少泽 on 16/12/8.
//  Copyright © 2016年 王少泽. All rights reserved.
//

#import "MoreNewsViewController.h"
#import "AppDelegate.h"

@interface MoreNewsViewController ()

@end

@implementation MoreNewsViewController
{
    UIWindow* _currentWindow;
    UIView* _newsFenlei;
    UIWindow* sh;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"新闻分类";
    
    UIBarButtonItem* selectInfo = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"NewsIcon"] style:UIBarButtonItemStylePlain target:self action:@selector(selectViewApper:)];
    self.navigationItem.rightBarButtonItem = selectInfo;
    
    
}
- (void)selectViewApper:(UIBarButtonItem* )sender
{
    
    sh = [UIApplication sharedApplication].keyWindow;
    
    _newsFenlei = [[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width, 0, 180, self.view.frame.size.height)];
    _newsFenlei.backgroundColor = [UIColor whiteColor];
    [_newsFenlei bringSubviewToFront:self.view];
    
    [UIView beginAnimations:nil context:nil];
    _newsFenlei.frame = CGRectMake(self.view.frame.size.width - 180, 0, 180, self.view.frame.size.height);
    [UIView commitAnimations];
    
    
    
    _currentWindow = [[UIWindow alloc]initWithFrame:self.view.bounds];
//    _currentWindow.backgroundColor = [UIColor yellowColor];
    [_currentWindow makeKeyAndVisible];
    [_currentWindow addSubview:_newsFenlei];
    UITapGestureRecognizer* tapView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeTheMain:)];
    [_currentWindow addGestureRecognizer:tapView];
    
    
//    if (newsFenlei.frame.origin.x == self.view.frame.origin.x) {
//        [UIView beginAnimations:nil context:nil];
//        newsFenlei.frame = CGRectMake(self.view.frame.size.width, 0, 180, self.view.frame.size.height);
//        [UIView commitAnimations];
//    }
//    else
//    {
//        
//        
//        
//    }
    
    
}

- (void)closeTheMain:(id)sender
{
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    _newsFenlei.frame = CGRectMake(self.view.frame.size.width-10, 0, 180, self.view.frame.size.height);
    [UIView commitAnimations];
    sleep(1);
    [self closeWindow];
}

- (void)closeWindow
{
    
    sleep(0.5);
    [_currentWindow resignKeyWindow];
//    _currentWindow = nil;
    [sh makeKeyAndVisible];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
